
import bpy



from 节点.全局控制.Node.节点和插座基类 import bl_节点基类
from 节点.Core import bl_UI配色
from 节点.Core import bl_Mesh

import engine.initLIB.load_dll as engineLib
import ctypes


engineLib.flexCAPI.f_创建排列对齐节点.restype = ctypes.c_bool





E_坐标排列方式枚举 = [
	("TYPE_自适应升序",	"自适应升序",	"", 'SORT_DESC',	0),
	("TYPE_自适应降序",	"自适应降序",	"", 'SORT_ASC',		1),
	("TYPE_最大升序",	"最大升序",		"", 'SORT_DESC',	2),
	("TYPE_最大降序",	"最大降序",		"", 'SORT_ASC',		3),
]

E_坐标对齐方式枚举 = [
	("TYPE_据中",	"据中",		"", 'ALIGN_CENTER',	0),
	("TYPE_左对齐",	"左对齐",	"", 'ALIGN_LEFT',	1),
	("TYPE_右对齐",	"右对齐",	"", 'ALIGN_RIGHT',	2),
	("TYPE_顶对齐",	"顶对齐",	"", 'SORT_DESC',	3),
	("TYPE_底对齐",	"底对齐",	"", 'SORT_ASC',		4),
	("TYPE_前对齐",	"前对齐",	"", 'SORT_DESC',	5),
	("TYPE_后对齐",	"后对齐",	"", 'SORT_ASC',		6),
]

def f_update_排列(self, context):
	data = list(str(self.m_坐标排列方式))
	engineLib.flexCAPI.f_node_传入BL数据(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), ctypes.py_object(data));
	if context :
		self.id_data.f_节点数据更新_更新树([self])

def f_update_对齐(self, context):
	data = list(str(self.m_坐标对齐方式))
	engineLib.flexCAPI.f_node_传入BL数据(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), ctypes.py_object(data));
	if context :
		self.id_data.f_节点数据更新_更新树([self])

class C_Node_排列对齐(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_排列对齐'
	bl_label = '排列对齐'
	
	m_坐标排列方式 = bpy.props.EnumProperty(items=E_坐标排列方式枚举, name="排列方式", default="TYPE_自适应升序", update=f_update_排列)
	m_坐标对齐方式 = bpy.props.EnumProperty(items=E_坐标对齐方式枚举, name="对齐方式", default="TYPE_据中", update=f_update_对齐)
	def init(self, context):
		super(C_Node_排列对齐, self).f_init(context)
		self.inputs.new('C_Socket_引用', name='var')
		self.outputs.new('C_NodeSocket_动态插座', name='var')
		self.f_toCPP();
		
	def f_toCPP(self):
		是否更新 = engineLib.flexCAPI.f_创建排列对齐节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		if 是否更新 :
			self.use_custom_color = True
			self.color = bl_UI配色.g_内部节点颜色
			
	def draw_buttons(self, context, layout):
		layout.prop(self, 'm_坐标排列方式')
		layout.prop(self, 'm_坐标对齐方式')


class C_NODE_MENU_排列对齐(bpy.types.Operator):
	bl_idname = 'node.global_node_coord_arrange_alignment'
	bl_label = '排列对齐'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_排列对齐', use_transform=True)
		return {'FINISHED'}























classes = (
	C_Node_排列对齐,
	C_NODE_MENU_排列对齐,

)

def register():
	for c in classes:
		bpy.utils.register_class(c)
		
def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)






